//
//  TreeNoodFindKValue.swift
//  LeetCode
//
//  Created by 刘彬彬 on 2021/2/25.
//  Copyright © 2021 LBB. All rights reserved.
//  二叉搜索树中第K小的元素

import Foundation
class TreeNoodFindKValue:NSObject {
    func findKValue(_ root:TreeNode, _ value:Int) -> TreeNode {
        if root.val == value {
            return root
        } else {
            let temp1:TreeNode = findKValue(root.left!, value)
            if temp1.val >= 0 {
                return temp1
            }
            let temp2:TreeNode = findKValue(root.right!, value)
            if temp2.val >= 0 {
                return temp2
            }
        }
        return root
    }
}
